<?php
namespace app\controllers;


use app\common\corelib\LocalUpload;
use app\logic\CourseLogic;
use app\logic\PaperLogic;
use yii;
//课程管理
class CourseController extends BackendController
{
    //淘淘拼音
    public function actionTaotao()
    {
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '课程管理';
        return $this->render('index', [
            'course_type'=>1,
            'course' => $courseLogic->getCourse(1,$query, $page),
            'query' => $query
        ]);
    }
    //淘转课堂
    public function actionNaughty()
    {
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '课程管理';
        return $this->render('index', [
            'course_type'=>7,
            'course' => $courseLogic->getCourse(7,$query, $page),
            'query' => $query
        ]);
    }
    //YCT
    public function actionYct()
    {
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '课程管理';
        return $this->render('index', [
            'course_type'=>2,
            'course' => $courseLogic->getCourse(2,$query, $page),
            'query' => $query
        ]);
    }
    //Hsk
    public function actionHsk()
    {
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '课程管理';
        return $this->render('index', [
            'course_type'=>3,
            'course' => $courseLogic->getCourse(3,$query, $page),
            'query' => $query
        ]);
    }
    //西语发音
    public function actionPronunciation()
    {
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '课程管理';
        return $this->render('index', [
            'course_type'=>4,
            'course' => $courseLogic->getCourse(4,$query, $page),
            'query' => $query
        ]);
    }
    //少儿西语
    public function actionChildren()
    {
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '课程管理';
        return $this->render('index', [
            'course_type'=>5,
            'course' => $courseLogic->getCourse(5,$query, $page),
            'query' => $query
        ]);
    }
    //Dele
    public function actionDele()
    {
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '课程管理';
        return $this->render('index', [
            'course_type'=>6,
            'course' => $courseLogic->getCourse(6,$query, $page),
            'query' => $query
        ]);
    }
    //添加课程
    public function actionAdd(){
        $courseLogic = new CourseLogic();
        if(!Yii::$app->request->post()){
            $course_type = Yii::$app->request->get('course_type', 0);
            if($course_type==1)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/taotao'), ' 添加课程' => ''];
            elseif($course_type==2)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/yct'), ' 添加课程' => ''];
            elseif($course_type==3)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/hsk'), ' 添加课程' => ''];
            elseif($course_type==4)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/pronunciation'), ' 添加课程' => ''];
            elseif($course_type==5)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/children'), ' 添加课程' => ''];
            elseif($course_type==6)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/dele'), ' 添加课程' => ''];
            elseif($course_type==7)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/naughty'), ' 添加课程' => ''];
            return $this->render('add', [
                'course_type'=>$course_type,
                'theme' => '/assets/',
                'actionUrl' => U('course/add')
            ]);
        }else{
            $params = Yii::$app->request->post('form');
            if($_FILES['course_pic']['name']){
                LocalUpload::go_upload($_FILES['course_pic']);
                $uploadresult = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
                $thumbs = LocalUpload::thumbs(100,100);
            }else{
                $uploadresult = '';
            }
            $logicRes = $courseLogic->addCourse($params,$uploadresult);
            if ($logicRes) {
                Yii::$app->getSession()->setFlash('success','新增课程成功');
                if($params['course_type']==1)
                    jump('course/taotao');
                elseif($params['course_type']==2)
                    jump('course/yct');
                elseif($params['course_type']==3)
                    jump('course/hsk');
                elseif($params['course_type']==4)
                    jump('course/pronunciation');
                elseif($params['course_type']==5)
                    jump('course/children');
                elseif($params['course_type']==6)
                    jump('course/dele');
                elseif($params['course_type']==7)
                    jump('course/naughty');

            } else {
                Yii::$app->getSession()->setFlash('error','新增课程失败');
                $this->goBack(Yii::$app->request->referrer);
            }
        }
    }
    //修改课程
    public function actionEdit(){
        $courseLogic = new CourseLogic();
        if(!Yii::$app->request->post()){
            $id = Yii::$app->request->get('course_id');

            $params = Yii::$app->request->get('form');
            if(!$params){
                $params = [];
            }
            if(!$id){
                $id = $params['course_id'];
            }

            $course = $courseLogic->getById($id);
            if($course['course_type']==1)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/taotao'), $course['course_name'] => '', '更新' => ''];
            elseif($course['course_type']==2)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/yct'), $course['course_name'] => '', '更新' => ''];
            elseif($course['course_type']==3)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/hsk'), $course['course_name'] => '', '更新' => ''];
            elseif($course['course_type']==4)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/pronunciation'), $course['course_name'] => '', '更新' => ''];
            elseif($course['course_type']==5)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/children'), $course['course_name'] => '', '更新' => ''];
            elseif($course['course_type']==6)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/dele'), $course['course_name'] => '', '更新' => ''];
            elseif($course['course_type']==7)
                $this->data['breadcrumbs'] = ['课程管理' => U('course/naughty'), $course['course_name'] => '', '更新' => ''];
            if(file_exists(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'web'.$course['course_pic'])){
                $course_pic = $course['course_pic'];
            }else{
                $course_pic = '/default.jpg';
            }
            $page = Yii::$app->request->get('page', 1);
            $chapter = $courseLogic->getChapterByCourse($id,$params,$page);
            $paperLogic = new PaperLogic();
            $paper = null;
            if($course['course_type']==1)
                $paper = $paperLogic->getPaperByType(4);
            elseif($course['course_type']==2)
                $paper = $paperLogic->getPaperByType(5);
            elseif($course['course_type']==3)
                $paper = $paperLogic->getPaperByType(6);
            elseif($course['course_type']==4)
                $paper = $paperLogic->getPaperByType(7);
            elseif($course['course_type']==5)
                $paper = $paperLogic->getPaperByType(8);
            elseif($course['course_type']==6)
                $paper = $paperLogic->getPaperByType(9);
            elseif($course['course_type']==7)
                $paper = $paperLogic->getPaperByType(3);
            return $this->render('edit', [
                'chapter' => $chapter,
                'paper'=>$paper,
                'course_pic' => $course_pic,
                'course'=>$course,
                'theme' => '/assets/',
                'actionUrl' => U('course/edit'),
            ]);
        }else {
            $params = Yii::$app->request->post('form');
            $id = Yii::$app->request->post('course_id');
            $course = $courseLogic->getById($id);
            if ($_FILES['course_pic']['name']) {
                LocalUpload::go_upload($_FILES['course_pic']);
                $uploadresult = '/uploads/' . LocalUpload::$filedir . '/' . LocalUpload::$filename;
                $thumbs = LocalUpload::thumbs(100, 100);
            } else {
                $uploadresult = '';
            }
            $logicRes = $courseLogic->editById($id, $params, $uploadresult);
            if ($logicRes) {
                Yii::$app->getSession()->setFlash('success', '更新课程成功');
                if ($course['course_type'] == 1)
                    jump('course/taotao');
                elseif($course['course_type']==2)
                    jump('course/yct');
                elseif($course['course_type']==3)
                    jump('course/hsk');
                elseif($course['course_type']==4)
                    jump('course/pronunciation');
                elseif($course['course_type']==5)
                    jump('course/children');
                elseif($course['course_type']==6)
                    jump('course/dele');
                elseif($course['course_type']==7)
                    jump('course/naughty');
            } else {
                Yii::$app->getSession()->setFlash('error', '更新课程失败');
                $this->goBack(Yii::$app->request->referrer);
            }
        }
    }
    //更改课程状态
    public function actionSaveStatus(){
        $id = Yii::$app->request->get('course_id');
        $courseLogic = new CourseLogic();
        $course = $courseLogic->getById($id);
        $logicRes = $courseLogic->saveStatus($id);
        if ($logicRes) {
            Yii::$app->getSession()->setFlash('success','更改状态成功');
        } else {
            Yii::$app->getSession()->setFlash('error','更改状态失败');
        }
        if($course['course_type']==1)
            return $this->redirect(U('course/taotao'));
        elseif($course['course_type']==2)
            return $this->redirect(U('course/yct'));
        elseif($course['course_type']==3)
            return $this->redirect(U('course/hsk'));
        elseif($course['course_type']==4)
            return $this->redirect(U('course/pronunciation'));
        elseif($course['course_type']==5)
            return $this->redirect(U('course/children'));
        elseif($course['course_type']==6)
            return $this->redirect(U('course/dele'));
        elseif($course['course_type']==7)
            return $this->redirect(U('course/naughty'));
    }
    //删除课程
    public function actionDelete(){
        $id = Yii::$app->request->get('course_id');
        $courseLogic = new CourseLogic();
        $course = $courseLogic->getById($id);
        $logicRes = $courseLogic->delete($id);
        if ($logicRes) {
            Yii::$app->getSession()->setFlash('success','删除成功');
        } else {
            Yii::$app->getSession()->setFlash('error','删除失败');
        }
        if($course['course_type']==1)
            return $this->redirect(U('course/taotao'));
        elseif($course['course_type']==2)
            return $this->redirect(U('course/yct'));
        elseif($course['course_type']==3)
            return $this->redirect(U('course/hsk'));
        elseif($course['course_type']==4)
            return $this->redirect(U('course/pronunciation'));
        elseif($course['course_type']==5)
            return $this->redirect(U('course/children'));
        elseif($course['course_type']==6)
            return $this->redirect(U('course/dele'));
        elseif($course['course_type']==7)
            return $this->redirect(U('course/naughty'));
    }
    //班级管理
    public function actionClass(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '班级管理';
        return $this->render('class-index', [
            'class' => $courseLogic->getClass($query, $page),
            'query' => $query
        ]);
    }
    //添加班级
    public function actionAddClass(){
        $courseLogic = new CourseLogic();
        if(!Yii::$app->request->post()){
            $paperLogic = new PaperLogic();
            $paper = $paperLogic->getPaperByType(3);
            $this->data['breadcrumbs'] = ['班级管理' => U('course/class'), ' 添加班级' => ''];
            return $this->render('add-class', [
                'paper'=>$paper,
                'theme' => '/assets/',
                'actionUrl' => U('course/add-class')
            ]);
        }else{
            $params = Yii::$app->request->post('form');
            $logicRes = $courseLogic->addClass($params);
            if ($logicRes) {
                Yii::$app->getSession()->setFlash('success','新增班级成功');
                jump('course/class');
            } else {
                Yii::$app->getSession()->setFlash('error','新增班级失败');
                $this->goBack(Yii::$app->request->referrer);
            }
        }
    }
    //Yct评论
    public function actionCommentYct(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '评论管理';
        return $this->render('comment-index-type', [
            'course_type'=>2,
            'comment' => $courseLogic->getCommentByCourseType(2,$query, $page),
            'query' => $query
        ]);
    }
    //淘淘拼音评论
    public function actionCommentTaotao(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '评论管理';
        return $this->render('comment-index-type', [
            'course_type'=>1,
            'comment' => $courseLogic->getCommentByCourseType(1,$query, $page),
            'query' => $query
        ]);
    }
    //Hsk评论
    public function actionCommentHsk(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '评论管理';
        return $this->render('comment-index-type', [
            'course_type'=>3,
            'comment' => $courseLogic->getCommentByCourseType(3,$query, $page),
            'query' => $query
        ]);
    }
    //西语发音评论
    public function actionCommentPronunciation(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '评论管理';
        return $this->render('comment-index-type', [
            'course_type'=>4,
            'comment' => $courseLogic->getCommentByCourseType(4,$query, $page),
            'query' => $query
        ]);
    }
    //少儿西语评论
    public function actionCommentChildren(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '评论管理';
        return $this->render('comment-index-type', [
            'course_type'=>5,
            'comment' => $courseLogic->getCommentByCourseType(5,$query, $page),
            'query' => $query
        ]);
    }
    //Dele评论
    public function actionCommentDele(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '评论管理';
        return $this->render('comment-index-type', [
            'course_type'=>6,
            'comment' => $courseLogic->getCommentByCourseType(6,$query, $page),
            'query' => $query
        ]);
    }
    //淘转课堂评论
    public function actionCommentNaughty(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '评论管理';
        return $this->render('comment-index-type', [
            'course_type'=>7,
            'comment' => $courseLogic->getCommentByCourseType(7,$query, $page),
            'query' => $query
        ]);
    }


    //其他评论
    public function actionComment(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $course_id = Yii::$app->request->get('course_id', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '评论管理';
        return $this->render('comment-index', [
            'course_id'=>$course_id,
            'comment' => $courseLogic->getComment($course_id,$query, $page),
            'query' => $query
        ]);
    }
    //删除评论
    public function actionDeleteComment(){
        $id = Yii::$app->request->get('comment_id');
        $courseLogic = new CourseLogic();
        $comment = $courseLogic->getCommentById($id);
        $logicRes = $courseLogic->deleteComment($id);
        if ($logicRes) {
            Yii::$app->getSession()->setFlash('success','删除成功');
        } else {
            Yii::$app->getSession()->setFlash('error','删除失败');
        }
        $this->goBack(Yii::$app->request->referrer);
    }
    //编辑班级
    public function actionEditClass(){
        $courseLogic = new CourseLogic();
        if(!Yii::$app->request->post()){
            $id = Yii::$app->request->get('class_id');
            $class = $courseLogic->getClassById($id);
            $this->data['breadcrumbs'] = ['班级管理' => U('course/class'), $class['class_name'] => '', '更新' => ''];
            $paperLogic = new PaperLogic();
            $paper = $paperLogic->getPaperByType(3);
            return $this->render('edit-class', [
                'class' => $class,
                'paper' => $paper,
                'theme' => '/assets/',
                'actionUrl' => U('course/edit-class'),
            ]);
        }else{
            $params = Yii::$app->request->post('form');
            $id = Yii::$app->request->post('class_id');
            $logicRes = $courseLogic->editClassById($id, $params);
            if ($logicRes) {
                Yii::$app->getSession()->setFlash('success','更新班级成功');
                jump('course/class');
            } else {
                Yii::$app->getSession()->setFlash('error','更新班级失败');
                $this->goBack(Yii::$app->request->referrer);
            }
        }
    }
    //删除班级
    public function actionDeleteClass(){
        $id = Yii::$app->request->get('class_id');
        $courseLogic = new CourseLogic();
        $logicRes = $courseLogic->deleteClass($id);
        if ($logicRes) {
            Yii::$app->getSession()->setFlash('success','删除成功');
        } else {
            Yii::$app->getSession()->setFlash('error','删除失败');
        }
            return $this->redirect(U('course/class'));
    }
    //添加章节
    public function actionAddChapter(){
        set_time_limit(0);
        $courseLogic = new CourseLogic();
        $params = Yii::$app->request->post('form');
        if($_FILES['chapter_pic']['name']){
            LocalUpload::go_upload($_FILES['chapter_pic']);
            $uploadresult = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
            $thumbs = LocalUpload::thumbs(100,100);
        }else{
            $uploadresult = '';
        }
        if($_FILES['chapter_video']['name']){
            LocalUpload::go_upload_video($_FILES['chapter_video']);
            $uploadresult1 = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
        }else{
            $uploadresult1 = '';
        }

        if($_FILES['chapter_test_video']['name']){
            LocalUpload::go_upload_video($_FILES['chapter_test_video']);
            $uploadresult2 = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
        }else{
            $uploadresult2 = '';
        }
        $logicRes = $courseLogic->addChapter($params,$uploadresult,$uploadresult1,$uploadresult2);
        if ($logicRes) {
            Yii::$app->getSession()->setFlash('success','新增章节成功');
            jump(['course/edit','course_id'=>$params['course_id']]);
        } else {
            Yii::$app->getSession()->setFlash('error','新增章节失败');
            $this->goBack(Yii::$app->request->referrer);
        }
    }
    //删除章节
    public function actionDeleteChapter(){
        $id = Yii::$app->request->get('chapter_id');
        $courseLogic = new CourseLogic();
        $chapter = $courseLogic->getChapterById($id);
        $logicRes = $courseLogic->deleteChapter($id);
        if ($logicRes) {
            Yii::$app->getSession()->setFlash('success','删除成功');
        } else {
            Yii::$app->getSession()->setFlash('error','删除失败');
        }
        return $this->redirect(U(['course/edit','course_id'=>$chapter['course_id']]));
    }
    //获取章节
    public function actionGetChapter(){
        $id = Yii::$app->request->post('chapter_id');
        $courseLogic = new CourseLogic();
        $chapter = $courseLogic->getChapterById($id);
        echo json_encode($chapter);
    }
    //编辑章节
    public function actionEditChapter(){
        set_time_limit(0);
        $courseLogic = new CourseLogic();
        $id = Yii::$app->request->post('chapter_id');
        $chapter = $courseLogic->getChapterById($id);
        $params = Yii::$app->request->post('form');
        if($_FILES['chapter_pic']['name']){
            LocalUpload::go_upload($_FILES['chapter_pic']);
            $uploadresult = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
            $thumbs = LocalUpload::thumbs(100,100);
        }else{
            $uploadresult = '';
        }
        if($_FILES['chapter_video']['name']){
            LocalUpload::go_upload_video($_FILES['chapter_video']);
            $uploadresult1 = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
        }else{
            $uploadresult1 = '';
        }

        if($_FILES['chapter_test_video']['name']){
            LocalUpload::go_upload_video($_FILES['chapter_test_video']);
            $uploadresult2 = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
        }else{
            $uploadresult2 = '';
        }
        $logicRes = $courseLogic->editChapter($id,$params,$uploadresult,$uploadresult1,$uploadresult2);
        if ($logicRes) {
            Yii::$app->getSession()->setFlash('success','编辑章节成功');
            jump(['course/edit','course_id'=>$chapter['course_id']]);
        } else {
            Yii::$app->getSession()->setFlash('error','编辑章节失败');
            $this->goBack(Yii::$app->request->referrer);
        }
    }
    //视频管理
    public function actionVideo(){
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $courseLogic = new CourseLogic();
        $this->data['breadcrumbs'] = '视频管理';
        return $this->render('video-index', [
            'video' => $courseLogic->getVideo($query, $page),
            'query' => $query
        ]);
    }
    //添加视频
    public function actionAddVideo(){
        set_time_limit(0);
        $courseLogic = new CourseLogic();
        if(!Yii::$app->request->post()){
            $this->data['breadcrumbs'] = ['视频管理' => U('course/video'), ' 添加视频' => ''];
            return $this->render('add-video', [
                'theme' => '/assets/',
                'actionUrl' => U('course/add-video')
            ]);
        }else{
            $params = Yii::$app->request->post('form');
            if($_FILES['chapter_pic']['name']){
                LocalUpload::go_upload($_FILES['chapter_pic']);
                $uploadresult = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
                $thumbs = LocalUpload::thumbs(100,100);
            }else{
                $uploadresult = '';
            }
            if($_FILES['chapter_video']['name']){
                LocalUpload::go_upload_video($_FILES['chapter_video']);
                $uploadresult1 = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
            }else{
                $uploadresult1 = '';
            }

            if($_FILES['chapter_test_video']['name']){
                LocalUpload::go_upload_video($_FILES['chapter_test_video']);
                $uploadresult2 = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
            }else{
                $uploadresult2 = '';
            }
            $logicRes = $courseLogic->addVideo($params,$uploadresult,$uploadresult1,$uploadresult2);
            if ($logicRes) {
                Yii::$app->getSession()->setFlash('success','新增视频成功');
                jump('course/video');
            } else {
                Yii::$app->getSession()->setFlash('error','新增视频失败');
                $this->goBack(Yii::$app->request->referrer);
            }
        }
    }
    //编辑视频
    public function actionEditVideo(){
        set_time_limit(0);
        $courseLogic = new CourseLogic();
        if(!Yii::$app->request->post()){
            $id = Yii::$app->request->get('chapter_id');
            $chapter = $courseLogic->getChapterById($id);
            $this->data['breadcrumbs'] = ['视频管理' => U('course/video'), $chapter['chapter_name'] => '', '更新' => ''];

            if(file_exists(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'web'.$chapter['chapter_pic'])){
                $chapter_pic = $chapter['chapter_pic'];
            }else{
                $chapter_pic = '/default.jpg';
            }
            return $this->render('edit-video', [
                'chapter' => $chapter,
                'chapter_pic' => $chapter_pic,
                'theme' => '/assets/',
                'actionUrl' => U('course/edit-video'),
            ]);
        }else {
            $id = Yii::$app->request->post('chapter_id');
            $params = Yii::$app->request->post('form');
            if($_FILES['chapter_pic']['name']){
                LocalUpload::go_upload($_FILES['chapter_pic']);
                $uploadresult = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
                $thumbs = LocalUpload::thumbs(100,100);
            }else{
                $uploadresult = '';
            }
            if($_FILES['chapter_video']['name']){
                LocalUpload::go_upload_video($_FILES['chapter_video']);
                $uploadresult1 = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
            }else{
                $uploadresult1 = '';
            }

            if($_FILES['chapter_test_video']['name']){
                LocalUpload::go_upload_video($_FILES['chapter_test_video']);
                $uploadresult2 = '/uploads/'.LocalUpload::$filedir.'/'.LocalUpload::$filename;
            }else{
                $uploadresult2 = '';
            }
            $logicRes = $courseLogic->editVideo($id,$params,$uploadresult,$uploadresult1,$uploadresult2);
            if ($logicRes) {
                Yii::$app->getSession()->setFlash('success','编辑视频成功');
                jump('course/video');
            } else {
                Yii::$app->getSession()->setFlash('error','编辑视频失败');
                $this->goBack(Yii::$app->request->referrer);
            }
        }

    }
    //删除视频
    public function actionDeleteVideo(){
        $id = Yii::$app->request->get('chapter_id');
        $courseLogic = new CourseLogic();
        $logicRes = $courseLogic->deleteChapter($id);
        if ($logicRes) {
            Yii::$app->getSession()->setFlash('success','删除成功');
        } else {
            Yii::$app->getSession()->setFlash('error','删除失败');
        }
        return $this->redirect(U('course/video'));
    }


}
